import { BaseItem } from "../../common/BaseItem";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ItemData } from "../../../resource/info/ItemData";
import { TowerInfoHideButton } from "../magicTower/TowerInfoHideButton";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { RolePlayer } from "../../../scene/player/entity/RolePlayer";
import { LayerManager } from "../../../manager/LayerManager";
import { TweenLite } from "../../../../../com/greensock/TweenLite";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class CopyMaterialCanvas
    
    export  class CopyMaterialCanvas /* flash.display.Sprite */
    {
        constructor(arg1: Boolean=true, arg2: int=1, arg3: int=4, arg4: int=4)
        {
            
            this._materials = new Vector.<BaseItem>();
            this._needFlutter = arg1;
            this._lineNum = arg2;
            this._columnsNum = arg3;
            this._materialKindNum = arg4;
            this.createChildren();
            return;
        }

        protected createChildren(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            while (loc3 < this._materialKindNum) 
            {
                loc1 = GlobalClass.getBitmap(ImagesConst.PackItemBg);
                loc1.x = 10 + 41 * loc3 % this._columnsNum;
                loc1.y = 33 + 40 * Math.floor(loc3 / this._columnsNum);
                this.addChild(loc1);
                loc2 = new BaseItem();
                loc2.setSize(32, 32);
                loc2.x = loc1.x + 3;
                loc2.y = loc1.y + 3;
                loc2.isDragAble = false;
                loc2.isDropAble = false;
                this.addChild(loc2);
                this._materials.push(loc2);
                ++loc3;
            }
            return;
        }

        public setMaterials(arg1: Array<any>): void
        {
            if (this._needFlutter) 
            {
                this.checkAddAndPlayEffect(arg1);
            }
            var loc1=0;
            while (loc1 < this._materials.length) 
            {
                if (loc1 < arg1.length) 
                {
                    this._materials[loc1].itemData = arg1[loc1] as ItemData;
                }
                else 
                {
                    this._materials[loc1].itemData = null;
                }
                ++loc1;
            }
            return;
        }

        public stretchView(arg1: TowerInfoHideButton): void
        {
            this._towerInfoHideButton = arg1;
            return;
        }

        /* internal  */checkAddAndPlayEffect(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            var loc4=false;
            loc2 = 0;
            while (loc2 < arg1.length) 
            {
                loc1 = arg1[loc2] as ItemData;
                loc3 = 0;
                while (loc3 < this._materials.length) 
                {
                    if (!this._materials[loc3].itemData || this._materials[loc3].itemData && this._materials[loc3].itemData.itemCode == loc1.itemCode) 
                    {
                        if (!this._materials[loc3].itemData || this._materials[loc3].itemData.itemAmount < loc1.itemAmount) 
                        {
                            LoaderManager.instance.load(loc1.itemInfo.url, this.onImageLoaded, 3, loc3);
                        }
                        break;
                    }
                    ++loc3;
                }
                ++loc2;
            }
            return;
        }

        /* internal  */onImageLoaded(arg1: ImageInfo): void
        {
            var loc4=null;
            var loc1=RolePlayer.instance.stagePointX;
            var loc2=RolePlayer.instance.stagePointY - 55;
            var loc3=arg1.extData as int;
            if (this._towerInfoHideButton && this._towerInfoHideButton.parent) 
            {
                loc4 = this._towerInfoHideButton.parent.localToGlobal(new Object /* flash.geom.Point */(this._towerInfoHideButton.x, this._towerInfoHideButton.y));
            }
            else 
            {
                loc4 = this.localToGlobal(new Object /* flash.geom.Point */(this._materials[loc3].x, this._materials[loc3].y));
            }
            var loc5;
            (loc5 = new Object /* flash.display.Bitmap */(arg1.bitmapData)).x = loc1;
            loc5.y = loc2;
            loc5.width = 32;
            loc5.height = 32;
            LayerManager.topLayer.addChild(loc5);
            TweenLite.to(loc5, 1.5, {"x": loc4.x, "y": loc4.y, "onComplete": this.onFlyComplete, "onCompleteParams":[loc5]});
            return;
        }

        /* internal  */onFlyComplete(arg1: Object /* flash.display.Bitmap */): void
        {
            if (arg1 && arg1.parent) 
            {
                arg1.parent.removeChild(arg1);
                arg1 = null;
            }
            return;
        }

        /* internal */ /* var */_materials: Vector.<BaseItem>;

        /* internal */ /* var */_lineNum: int;

        /* internal */ /* var */_columnsNum: int;

        /* internal */ /* var */_materialKindNum: int;

        /* internal */ /* var */_needFlutter: Boolean;

        /* internal */ /* var */_towerInfoHideButton: TowerInfoHideButton;
    }
